<template>
  <li class="blog-item">
    <div class="blog-info">
      <div class="blog-info-top">
        <nuxt-link class="blog-info-userAvatar" :to="'/user/' + data.user_id" target="_blank">
          <img :src="data.avatar" alt="">
        </nuxt-link>
        <nuxt-link class="author" :to="'/user/' + data.user_id" target="_blank">
          {{ data.name }}
        </nuxt-link>
        <span class="time">
          {{ $moment(data.createTime).fromNow() }}
        </span>
        <!--3表示热门加精选，2表示热门，1表示精选，0表示普通文章-->
        <span v-if="[1, 3].includes(data.importance)" class="sift mark">
          精
        </span>
        <span v-if="[1, 2].includes(data.importance)" class="hot mark">
          热
        </span>
        <span v-if="[4].includes(data.importance)" class="top mark">
          顶
        </span>
      </div>
      <div class="blog-info-title">
        <nuxt-link :to="'/article/' + data.id" target="_blank">
          {{ data.title }}
        </nuxt-link>
      </div>
      <div class="blog-info-bottom">
        <a v-if="userData && data.user_id === userData.userId" class="iconfont icon-ic-liulan">
          {{ data.pv }}
        </a>
        <a class="iconfont icon-ic-like">
          {{ data.supportCount }}
        </a>
        <a class="iconfont icon-ic-comment">
          {{ data.commentCount }}
        </a>
        <nuxt-link
          v-for="(innerItem, index) of data.tags"
          :key="index"
          class="tag"
          :to="'/tag/' + innerItem.id + '?name=' + innerItem.name"
        >
          # {{ innerItem.name }}
        </nuxt-link>
        <a
          v-if="userData && data.user_id === userData.userId && currentRouteName === 'user-id'"
          class="iconfont el-icon-delete"
          @click="$emit('modifyArticleStatus', data.id, 'delete')"
        >
          删除
        </a>
      </div>
    </div>
    <nuxt-link class="blog-cover" :to="'/article/' + data.id" target="_blank">
      <img :src="data.article_img" alt="">
    </nuxt-link>
  </li>
</template>

<script>
export default {
  name: 'BlogItem',
  props: {
    data: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      currentRouteName: this.$route.name
    }
  },
  computed: {
    userData() {
      return this.$store.state.user.userData
    }
  }
}
</script>

<style scoped lang="scss">
@import "~assets/css/article/articleItem";
</style>
